#ifndef	_GLOVARDEF_H
#define	_GLOVARDEF_H
//
#ifdef __cplusplus
extern "C" {
#endif
//
#pragma  pack (1)
//
#include "GenTypeDef.h"
//
//*************************************************************
//  -----Please add your globle variable definition here----
//  ------for example below-----------------
//*************************************************************
//-------globle  variable definiton----
// debug
char JS_RTT_UpBuffer[4096];    // J-Scope RTT Buffer
int  JS_RTT_Channel = 1;       // J-Scope RTT Channel
//
#if (DEBUG_FOC_OUTPUT == 1)
LONG   DebugBuf_0[DB_FOC_DATA_SIZE]={0};
LONG   DebugBuf_1[DB_FOC_DATA_SIZE]={0};
LONG   DebugBuf_2[DB_FOC_DATA_SIZE]={0};
LONG   DebugBuf_3[DB_FOC_DATA_SIZE]={0};
uSHORT DBCnt  = 0;
#endif
// system
uCHAR   g_Cnt1ms = 0;                   // the system 1ms counter
uLONG   g_CntPWM = 0;                   // PWM counter.unit:1 PWM cycle
// speed and Ibus
LONG    g_SetSpeed = 0;                 // the motor setting speed,unit: 1RPM
LONG    g_ActualSpeed = 0;              // the motor actual speed,unit: 1RPM
uLONG   g_SpeedRangeMin = 0;            // the minimum of speed range,unit:1RPM
uSHORT  g_SetIBus = 0;                  // the motor setting IBus,unit: 1A
uSHORT  g_ActualIBus = 0;               // the motor actual IBus,unit: 1A
// PID
LONG    g_Speed_PID_Data = 0;           // the speed PID data
LONG    g_Curr_D_PID_Data = 0;          // the ID PID data
LONG    g_Curr_Q_PID_Data = 0;          // the IQ PID data
LONG    g_IBus_PID_Data = 0;            // the Ibus PID data
//
uSHORT  g_Speed_PID_Cycle = 0;          // the speed PID cycle
// PWM 
uLONG   g_PWM_Frequency = 0;            // PWM frequency,unit: 1hz
uLONG   g_PWM_Period = 0;               // PWM period,unit: 1ns
uLONG   g_PWMLoadData = 0;              // PWM load data
uCHAR   g_PWM_CCR_Duty = 0;             // PWM CCR duty
uSHORT  g_PWM_CCR_Data = 0;             // PWM CCR data
uCHAR   g_PWM_InverseIndex = 0;         // the index of pwm invertion
// ADC
uSHORT  g_VoltageRES1 = 0;              // the reserve ADC data
uSHORT  g_VoltageRES2 = 0;              // the reserve ADC data
uSHORT  g_VoltageMotor = 0;             // the ADC data of the VM Voltage 
uSHORT  g_VoltageSpeed = 0;             // the ADC data of the Speed Voltage
uSHORT  g_VoltageMosTemp = 0;           // the ADC data of the MOS Temperature Voltage
uSHORT  g_ADC_RegularConvertedValueTab[16] = {0};   // the ADC data buffer of regular channel
uSHORT  g_ADC_InjectedConvertedValueTab[4] = {0};   // the ADC data buffer of inject channel
uSHORT  g_CurrIBusAVG = 0;              // the ADC data of the average IBUS Voltage
SHORT   g_CurrIBusBuf[2] = {0};         // the ADC data of the IBUS Voltage
LONG    g_CurrIBus_Offset = 0;          // the IBus offset current
uCHAR   g_CurrOffset_Cnt = 0;           // the offset current counter
uLONG   g_ADC_ExternalTrigSource = ADC_ExternalTrigInjec_TMR1_CC4;
// motor
uCHAR   g_MotorPolePairs = 0;           // the number of motor pole-pairs
uCHAR   g_ForRevDir = 0;                // the rotate direction, 0: forward; 1:reverse
uCHAR   g_ForRevDirUpdate = 0xFF;       // the rotate direction, 0: forward; 1:reverse
uCHAR 	g_DirRotCnt = 0;                // the rotate direction counter
// Key
uSHORT 	g_Key1Cnt = 0;                  // the key1 counter
uSHORT 	g_Key2Cnt = 0;                  // the key2 counter
// angle
SHORT   g_Angle = 0;                    // the electrical angle
// circle
uLONG   CircleModulation = 0;           // the maximum value of vector circle
uCHAR   CircleStartIndex = 0;           // the start index  of vector circle
// protect
uSHORT  g_CntOCP = 0;                   // the OCP counter
uSHORT  g_CntLRCP = 0;                  // the LRCP counter
uSHORT  g_CntLRPP = 0;                  // the LRPP counter
uSHORT  g_CntUVP = 0;                   // the UVP counter
uSHORT  g_CntOVP = 0;                   // the OVP counter
uSHORT  g_CntOTP = 0;                   // the OTP counter
uSHORT  g_CntLED = 0;                   // the LED counter
uSHORT  g_DelayTimeOCP = 0;             // the OCP delay time
uSHORT  g_DelayTimeUVP = 0;             // the UVP delay time
uSHORT  g_DelayTimeOVP = 0;             // the OVP delay time
uSHORT  g_DelayTimeOTP = 0;             // the OTP delay time
uSHORT  g_CntACP = 0;										// the ACP counter
uSHORT  g_DelayTimeACP = 0;							// the ACP delay time
uSHORT  g_DelayTimeLED = 0;             // the LED delay time
// Stage
T_STAGE  g_Stage = INIT_STAGE;          // the initial system stage 
// Bool
T_BOOL   ResultFS = FALSE;              // the result of the first stage
T_BOOL   ResultBS = FALSE;              // the result of the brake stage
// Index
T_INDEX  INDEX_FS = INDEX_START;        // the index of the first stage
T_INDEX  INDEX_BS = INDEX_START;        // the index of the brake stage
T_FOC_INDEX INDEX_FOC = LOCATION;       // the index of the FOC
// Flag
T_DELAY    delay;                       // the delay flag
T_TIMEOUT  timeout;                     // the timeout flag
T_PROTECT  protect;                     // the protect flag
T_FLAG     flag;                        // the other flag
// FOC
T_CurrComps  Curr_A_B;                  // the current A and B
T_CurrComps  Curr_ALFA_BETA;            // the current Alfa and Beta
T_CurrComps  Curr_D_Q;                  // the current D and Q
T_CurrComps  Curr_D_Q_REF;              // the reference current D and Q
T_VoltComps  Volt_D_Q;                  // the voltage D and Q
T_VoltComps  Volt_ALFA_BETA;            // the reference voltage D and Q
T_TrigComps  Trig;                      // the trigonometric value
T_SVPWMComps  SVPWM;                    // the return value of SVPWM
// PID
T_INC_PID  SpeedPID;                    // the speed PID
T_INC_PID  IBusPID;                     // the IBus PID
T_INC_PID  Curr_D_PID;                  // the ID PID
T_INC_PID  Curr_Q_PID;                  // the IQ PID
// SMC
T_SLIDE_MODE_CTRL  SMC;                 // the Sliding-Mode controller
// MDM
T_MOTOR_DIG_MODE   MDM;                 // the motor digital mode
//
//----------end globle data definition-------------------
//
#ifdef __cplusplus
}
#endif
//
#endif	//_GLOVARDEF_H

